/* GUI CONVERTED from rsm1md.p (converter v1.76) Fri Dec 14 05:08:32 2001 */
/* rsm1md.p - Supplier Schedules - Calculate the first month Monday           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.4 $                                                           */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3    LAST MODIFIED: 03/18/93      BY: WUG *G776*               */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00      BY: *N0KP* Mark Brown        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.4 $    BY: Jean Miller           DATE: 12/11/01  ECO: *P03N*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* CALCULATE THE FIRST MONTH MONDAY DATE ON OR BEFORE,
 * OR ON OR AFTER THE INPUT DATE */

define input  parameter input_date as date.
define input  parameter before     as logical.
define output parameter mth_1st_mon_dt as date.

define variable work_dt as date.

mth_1st_mon_dt = date(month(input_date),1,year(input_date)).
mth_1st_mon_dt = mth_1st_mon_dt + ((9 - weekday(mth_1st_mon_dt)) modulo 7).

if before then do:
   if input_date < mth_1st_mon_dt then do:
      mth_1st_mon_dt = date(month(input_date - 15),1,year(input_date - 15)).
      mth_1st_mon_dt = mth_1st_mon_dt + ((9 - weekday(mth_1st_mon_dt)) modulo 7).
   end.
end.
else do:
   if input_date > mth_1st_mon_dt then do:
      work_dt = mth_1st_mon_dt + 45.
      mth_1st_mon_dt = date(month(work_dt),1,year(work_dt)).
      mth_1st_mon_dt = mth_1st_mon_dt + ((9 - weekday(mth_1st_mon_dt)) modulo 7).
   end.
end.
